﻿using System;
using System.Collections.Generic;
using Lextm.SharpSnmpLib;
using SNMS.Manager.S_DAL.Entities;
using System.Net;

namespace SNMS.Manager.Infrastructure
{
    public class DeviceSyncEngine
    {
        private IList<SyncFlowItem> syncFlows;

        public DeviceSyncEngine() : 
            this(new TimeSpan(1, 0, 0, 0), VersionCode.V2) { }
        public DeviceSyncEngine(TimeSpan interval, VersionCode version) : 
            this(interval, version, new OctetString("public")) { }
        public DeviceSyncEngine(TimeSpan interval, VersionCode version, OctetString community) :
            this(interval, version, community, 161) { }
        
        public DeviceSyncEngine(TimeSpan interval, VersionCode version,OctetString community,int port) {
            DeviceDiscoverer discoverer = new DeviceDiscoverer();
            var devices = discoverer.Discover(version);
            foreach (var device in devices) {
                var item = new SyncFlowItem() {
                    Interval = interval,
                    Version = version,
                    Community = community,
                    Port = port,
                    Device = device,
                    IPEndPoint = new IPEndPoint(IPAddress.Parse(device.DeviceIpAddress), port)
                };
                this.syncFlows.Add(item);
            }
        }

        public DeviceSyncEngine(Device device) : 
            this(device, new TimeSpan(1, 0, 0, 0)) { }
        public DeviceSyncEngine(Device device, TimeSpan interval) : 
            this(device, interval, VersionCode.V2) { }
        public DeviceSyncEngine(Device device, TimeSpan interval, VersionCode version) : 
            this(device, interval, version, new OctetString("public")) { }
        public DeviceSyncEngine(Device device, TimeSpan interval, VersionCode version, OctetString community) : 
            this(device, interval, version, new OctetString("public"), 161) { }
        
        public DeviceSyncEngine(Device device, TimeSpan interval, VersionCode version, OctetString community, int port) {
            throw new NotImplementedException();
        }

        public DeviceSyncEngine(IList<Device> devices, TimeSpan interval) : 
            this(devices, interval, VersionCode.V2) { }
        public DeviceSyncEngine(IList<Device> devices, TimeSpan interval, VersionCode version) : 
            this(devices, interval, version, new OctetString("public")) { }
        public DeviceSyncEngine(IList<Device> devices, TimeSpan interval, VersionCode version, OctetString community) : 
            this(devices, interval, version, new OctetString("public"), 161) { }
        
        public DeviceSyncEngine(IList<Device> devices, TimeSpan interval, VersionCode version, OctetString community,int port) {
            throw new NotImplementedException();
        }
        
        public DeviceSyncEngine(IList<SyncFlowItem> items) {
            throw new NotImplementedException();

            // TODO:Main implemention of DeviceSyncEngine class.
        }

        public void Begin() { }
    }
}
